import request from '@/utils/request.js'

//发布新帖子(可用)
export const makePostService = (post)=>{
    return request.post('/api/posts', post.value);
}

//查询帖子列表
export const listPostService = (Data)=>{
    const params = {};  
    for (let key in Data) { params[key] = Data[key]; }  
    console.log(params); 
    return request.get('/api/posts/list', {params});
}

//删除帖子
export const deletePostService = (postId) => {
    return request.delete('/api/posts?postId=' + postId);
}

//获取帖子详情
export const postInfoService = (Data)=>{
    const params = {};  
    for (let key in Data) {  
        if (typeof Data[key] === 'object' && Data[key] !== null) {  
            // 对于对象进行深度拷贝  
            params[key] = JSON.parse(JSON.stringify(Data[key]));  
        } else {  
            params[key] = Data[key];  
        }  
    }  
    console.log(params);  
    return request.get('/api/posts/post', {params})
}

//修改帖子
export const postUpdateService = (Data)=>{
    return request.put('/api/posts', Data);
}